Skip to content

feat: add 1Password SecretsProvider#18

Merged
klaidliadon merged 10 commits intomasterfrom
onepassword-provider
Apr 30, 2026
Merged

feat: add 1Password SecretsProvider#18
klaidliadon merged 10 commits intomasterfrom
onepassword-provider

Conversation

@klaidliadon
Copy link
Copy Markdown
Contributor

@klaidliadon klaidliadon commented Apr 25, 2026

Summary

  • Adds onepassword provider that resolves op://<vault>/<item>/<field> references by shelling out to the op CLI. Plan-agnostic — works on Personal, Teams, and Business — and reuses whatever auth the CLI is configured with (biometric desktop integration, op signin session, or OP_SERVICE_ACCOUNT_TOKEN).
  • Supports a backwards-compat shorthand via WithDefaultPath(vault, item): callers configured with a default path can write $SECRET:KEY instead of $SECRET:op://.... Drop-in for configs migrating from the env provider's $SECRET:KEY format.
  • Backfills per-provider READMEs for gcp and env so docs are uniform; root README becomes a thin index linking to each provider's README.
  • Splits _examples into per-provider binaries (cmd/gcp/, cmd/onepassword/) with matching make run-gcp / make run-onepassword targets.

Why a CLI wrapper instead of the Go SDK

We initially tried github.com/1password/onepassword-sdk-go but it's overkill for this use case:

  • Plan-agnostic. The SDK supports both service account tokens (Business plan only) and desktop integration. The CLI works with all of those plus op signin sessions, with one auth path.
  • No vendored runtime. SDK ships a WASM core (~10 MB) executed via wazero; CLI wrapper is plain os/exec.
  • Better local-dev UX. Devs tap Touch ID once via desktop integration; secrets resolve. No service account tokens to copy into dotfiles.
  • Matches existing repo pattern. The gcp provider already shells out to gcloud for project-number resolution.

Design notes

  • Reference format: pass-through by default. Callers write $SECRET:op://vault/item/field. Provider is stateless beyond the located op binary.
  • Default-path shorthand: opt-in via WithDefaultPath(vault, item). With it set, bare names like $SECRET:KEY resolve as op://<vault>/<item>/KEY. Bare names without a configured default error out explicitly rather than producing a malformed URI.
  • Auth: delegated entirely to op. No env vars, no constructor knobs.
  • Startup auth check: NewSecretsProvider(ctx) runs op vault list to fail fast if the CLI cannot authenticate. (op whoami is not used — it doesn't trigger biometric desktop integration and reports "not signed in" even when the CLI works fine.)
  • Timeout: 10s per call. Includes any biometric prompt — interactive sign-in via eval "$(op signin)" skips the prompt for batch contexts.
  • No Close(): there's no persistent resource to release.
  • Functional options: chosen over positional args so the zero-config form (NewSecretsProvider(ctx)) stays untouched and future knobs can be added without breaking signatures.

Verification

  • go build ./...
  • make test ✓ (existing tests pass; no new tests — matches the existing pattern of untested SDK/CLI-wrapper providers)
  • make lint ✓ 0 issues
  • End-to-end smoke test on macOS with biometric desktop integration ✓ (resolved op://cloudsecrets-test/db/{username,password} via make run-onepassword).

Test plan

Steps to reproduce the smoke test are in onepassword/README.md → Try the example:

  • Install op CLI, enable desktop integration (or run eval "$(op signin)")
  • Provision a throwaway vault + item via the README's op vault create / op item create snippet
  • cd _examples && make run-onepassword
  • Confirm hydrated config prints test-user / hunter2 instead of $SECRET:op://... placeholders

- Move existing example to cmd/gcp/main.go
- Add cmd/onepassword/main.go for the new 1Password provider
- Replace `make run` with `make run-gcp` and `make run-onepassword`
The Go SDK (github.com/1password/onepassword-sdk-go) requires service
account tokens, available only on 1Password Business. Shelling out to
the `op` CLI works on every plan and reuses whatever auth the CLI is
configured with — biometric desktop integration, `op signin` sessions,
or service account tokens.

- Drops the SDK and its WASM/wazero core (~10 MB binary impact)
- Constructor no longer takes ctx (no client to set up)
- README rewritten to explain CLI install and auth modes
NewSecretsProvider now takes context.Context and runs `op vault list`
to fail fast if the CLI cannot authenticate. Misconfigured environments
surface their auth errors at boot, not on the first secret fetch.

`op vault list` is used instead of `op whoami` because the latter does
not trigger biometric desktop integration and reports "not signed in"
even when the CLI works fine via the desktop app.

README expanded to walk through the install-quit-restart-toggle
sequence required to enable biometric desktop integration on macOS.
@klaidliadon klaidliadon marked this pull request as ready for review April 25, 2026 20:15
@klaidliadon klaidliadon force-pushed the onepassword-provider branch from 75a4caf to 21615a2 Compare April 25, 2026 20:36
@klaidliadon klaidliadon requested a review from a team April 25, 2026 20:36
Configures a default vault/item so callers can write `$SECRET:KEY`
instead of `$SECRET:op://vault/item/KEY`. Useful for migrating configs
that previously resolved bare names via the env provider.

Resolution rule in FetchSecret:
- Secret IDs starting with "op://" pass through unchanged.
- Bare names get prepended with "op://<defaultVault>/<defaultItem>/".
- Bare names without a configured default path return an explicit
  error rather than producing a malformed URI for op read.
Copy link
Copy Markdown
Contributor

@VojtechVitek VojtechVitek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@klaidliadon klaidliadon merged commit 130154c into master Apr 30, 2026
4 checks passed
@klaidliadon klaidliadon deleted the onepassword-provider branch April 30, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants